package com.cleaningcloud.common.security.utils;

import com.cleaningcloud.common.core.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * packageName com.cleaningcloud.common.security.utils
 *
 * @author 字典转换
 * @version JDK 8
 * @className SubjectConversionUtils
 * @date 2025-08-13
 * @description TODO
 */
public class SubjectConversionUtils {

    public static String conversion(String subjectIds) {
        try {
            List<String> str = new ArrayList<>();
            if (StringUtils.isNotEmpty(subjectIds)) {
                for (String s : subjectIds.split(",")) {
                    String subject = SubjectUtils.getSubjectCache(s);
                    if (StringUtils.isNotEmpty(subject)) {
                        str.add(subject);
                    }
                }
                return String.join("/", str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static String conversionRegexp(String subjectIds) {
        if (StringUtils.isNotEmpty(subjectIds)) {
            List<String> str = new ArrayList<>();
            for (String s : subjectIds.split("\\|")) {
                str.add("(^|,|)" + s + "(^|,|)");
            }
            return String.join("|", str);
        }
        return null;
    }
}